﻿var weightForDistrictZZZInfoList;
var dateDistrictZZZInfoList = new Ext.form.Label({ width: 300 });
var dunDistrictZZZInfoList = new Ext.form.Label({ width: 300 });

function zzzWeightForDistrict() {
    if (Ext.getCmp('DistrictZZZwindow') == null) {
        var panel = new Ext.Panel({

            region: 'center',
//            title: '中转站按区统计',
            anchor: '100% 100%',
            closable: true,
            autoScroll: true,
            containerScroll: true,
            //margins: '0 0 0 5',
            border: false,
            iconCls: 'nav',
            items: [createConditionsForDistrictZZZ(), {
                layout: 'fit',
                items: [createItemsForDistrictZZZ()]
            }]
        });
        var window = new Ext.Window({
            title: "中转站按区统计",
            id: 'DistrictZZZwindow',
            layout: 'fit',       //弹出窗口内布局会充满整个窗口;
            width: 800,          //设置窗口大小;
            height: 400,
            items: panel         //默认会生成Ext.Panel类型的对象;并且随窗口大小改变而改变;
        });
        window.show();
    }


    updataDataForDistrictZZZ(dataFormat(new Date(), "yyyy-MM-dd"), "");
}


function updataDataForDistrictZZZ(dataPara, typePara) {
    weightForDistrictZZZInfoList.removeAll();
    weightForDistrictZZZInfoList.load({
        params: { dateString: dataPara, type: "中转站", typeLJ: typePara, op: 'GetDistrictWeightAllBh' }
                    , callback: function (records, options, success) {
                        if (success) {
                            dateDistrictZZZInfoList.setText( records[0].get("dateAll"));
                            dunDistrictZZZInfoList.setText(records[0].get("weightAll"));
                        }
                    }
    });
    
}

function createConditionsForDistrictZZZ() {
    return new Ext.Panel({
//        labelAlign: 'top',
        frame: true,
        bodyStyle: 'padding:0px 0px 0',
        items: [{
            //                                    columnWidth: .5,
            height: 30,
            layout: { type: 'hbox' },
            items: [
                                    {
                                        width: 100,
                                        xtype: "radio",
                                        name: "sex",
                                        boxLabel: "今日",
                                        id: "date1",
                                        checked: true

                                    }, {
                                        width: 100,
                                        xtype: "radio",
                                        name: "sex",
                                        boxLabel: "昨日",
                                        id: "date2"

                                    }, {
                                        width: 100,
                                        xtype: "label"
                                    },
                                    dateDistrictZZZInfoList]
        },

                                {
                                    //                                    columnWidth: .5,
                                    height: 30,
                                    layout: { type: 'hbox' },
                                    items: [
                                    {
                                        xtype: "label",
                                        width: 80,
                                        text: '中转站类型：'
                                    },
                                    initTYPELJ(3), 
                                    {
                                        width: 50,
                                        xtype: "label"
                                    },
                                    dunDistrictZZZInfoList]

                                }],
        buttonAlign: 'center',
        buttons: [{
            text: "查询",
            name: "button",
            handler: function () {
                var dunDate;
                if (Ext.getCmp('date1').checked) {
                    var yesterday = new Date();
                    dunDate = dataFormat(yesterday, "yyyy-MM-dd");
                }
                if (Ext.getCmp('date2').checked) {
                    var yesterday = new Date();
                    yesterday.setTime(yesterday.getTime() - 3600 * 1000 * 24);
                    dunDate = dataFormat(yesterday, "yyyy-MM-dd");
                }
//                if (Ext.getCmp('date3').checked) {
//                    if (Ext.getCmp('dateSearch').getValue() == "") {
//                        Ext.MessageBox.alert("提示", "请选择日期");
//                    } else {
//                        dunDate = dataFormat(Ext.getCmp('dateSearch').getValue(), "yyyy-MM-dd");
//                    }
//                }
//                if (Ext.getCmp('date4').checked) {
//                    if (Ext.getCmp('monthSearch').getValue() == "") {
//                        Ext.MessageBox.alert("提示", "请选择月份");
//                    } else {
//                        dunDate = dataFormat(Ext.getCmp('monthSearch').getValue(), "yyyy-MM"); ;
//                    }

//                }
                updataDataForDistrictZZZ(dunDate, Ext.get('cmbTypeLJ').getValue(), "中转站");
            }
        }]
    });
}

//function getVehicleWeight(clientName, name) {
//    tabPanel = new Ext.TabPanel({

//        fullscreen: true,
//        activeTab: 0,
//        defaults: {
//            styleHtmlContent: true
//        },
//        items: [
//            {
//                title: '全部',
//                html: '<iframe src="./html/WeightVehicle.aspx?clientName=' + clientName + '&dateString=' + document.getElementById("ljSearchData").value + '&name=' + name + ' "width="100%" height="100%"></iframe>'
//            }
//            ]
//    });

//    var window = new Ext.Window({
//        title: userName,
//        layout: 'fit',       //弹出窗口内布局会充满整个窗口;
//        width: 500,          //设置窗口大小;
//        height: 300,
//        items: tabPanel         //默认会生成Ext.Panel类型的对象;并且随窗口大小改变而改变;
//    });
//    window.show();
//}
//function rMenu2Fn(bb) {
//    alert(bb);
//}
function createItemsForDistrictZZZ() {
    //    var sm = new Ext.grid.CheckboxSelectionModel();
    var cm = new Ext.grid.ColumnModel([
        { header: '地区', dataIndex: 'name', sortable: true, width: 60 },
    //        { header: '报警类型', dataIndex: 'Alarm_Type', sortable: true, renderer: GetAlarmTypeString, width: 64 },
        {header: '吨数', dataIndex: 'dunCount', sortable: true, width: 58 },
        {
            header: "操作",
            width: 150,
            dataIndex: 'operation',
            align: 'center',
            renderer: function (value, cellmeta, record, rowIndex, columnIndex, store) {
//                return "<button type='button' onclick='rMenu1Fn(" + store + "," + rowIndex + ")'>中转站详情</button>"
//                    + "<button type='button' onclick='getVehicleWeight('aa')'>车辆详情</button>";
            }
        }]);

    // 数据源
    weightForDistrictZZZInfoList = new Ext.data.Store({
        url: "../Json/JsonGetWeightInfoList.ashx",
        reader: new Ext.data.JsonReader(
                { root: 'data' },
                Ext.data.Record.create([{ name: 'name' }, { name: 'dunCount' }, { name: 'dateAll' }, { name: 'weightAll'}])
            )
    });

    return new Ext.grid.GridPanel({
        anchor: '100%',
        layout: 'fit',
        enableHdMenu: false,
        autoScroll: true,
        containerScroll: true,
        autoHeight: true,
        //title: '报警列表',
        loadMask: { msg: '正在加载数据，请稍侯……' },
        //el: 'grid',
        store: weightForDistrictZZZInfoList,
        cm: cm,
        //bbar: bbar,
        bodyStyle: 'height:100%',
        viewConfig: {
            forceFit: true
        }
    });

}

//function initTYPELJ() {

//    //var carState = [["全部", "全部"], ["在线", "在线"], ["离线", "离线"]];厨余垃圾处理厂/其他垃圾处理厂/有害垃圾处理厂
////    厨余垃圾中转站 / 其他垃圾中转站 / 有害垃圾中转站 / 
////    厨余垃圾处理厂 / 其他垃圾处理厂 / 有害垃圾处理厂
//    var carState = [["", "全部"], ["厨余垃圾中转站", "厨余垃圾中转站"], ["其他垃圾中转站", "其他垃圾中转站"], ["有害垃圾中转站", "有害垃圾中转站"]];
//    var proxy = new Ext.data.MemoryProxy(carState);
//    var Type_Car = Ext.data.Record.create([{ name: "cid", type: "string", mapping: 0 }, { name: "cname", type: "string", mapping: 1}]);
//    var reader = new Ext.data.ArrayReader({}, Type_Car);
//    var store = new Ext.data.Store({
//        proxy: proxy,
//        reader: reader//,
//        //autoLoad:true
//    });
//    store.load();
//    //定义一个下拉框
//    var cmbCarState = new Ext.form.ComboBox({
//        id: 'cmbTypeLJ',
//        width: 180,
//        allowBlank: false,
//        triggerAction: "all", //是否开启自动查询功能
//        store: store, //定义数据源
//        displayField: "cname", //关联某一个逻辑列名作为显示值
//        valueField: "cid", //关联某一个逻辑列名作为实际值
//        mode: "local", //如果数据来自本地用local 如果来自远程用remote默认为remote
//        emptyText: "请选择状态"//没有选择时候的默认值

//    });
//    Ext.getCmp("cmbTypeLJ").setValue("");
//    return cmbCarState;
//}

